package com.some;

import java.util.Scanner;

public class Solution2 {
    public void dianWaiMai() {
        Scanner scanner = new Scanner(System.in);
        //商品数量
        int storeNum = scanner.nextInt();
        //商品原价
        int[] price1 = new int[storeNum];
        for (int i = 0; i < storeNum; i++) {
            price1[i] = scanner.nextInt();
        }
        //商品折扣价
        int[] price2 = new int[storeNum];
        for (int i = 0; i < storeNum; i++) {
            price2[i] = scanner.nextInt();
        }
        //折扣规则数量
        int priceNum = scanner.nextInt();
        //满减参数
        int[] countNum = new int[priceNum];
        for (int i = 0; i < priceNum; i++) {
            countNum[i] = scanner.nextInt();
        }
        //满减钱数
        int[] deMoney = new int[priceNum];
        for (int i = 0; i < priceNum; i++) {
            deMoney[i] = scanner.nextInt();
        }
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < storeNum; i++) {
            //原价
            int agoPrice = price1[i];
            //折扣价
            int countPrice = price2[i];
            for (int j = priceNum; j > 0; j--) {
                //能满减的情况
                if (agoPrice >= countNum[j - 1]) {
                    agoPrice -= deMoney[j - 1];
                    String s;
                    if (agoPrice == countPrice) {
                        s = "B";
                    } else if (agoPrice < countPrice) {
                        s = "M";
                    } else {
                        s = "Z";
                    }
                    res.append(s);
                    break;
                }
            }
            //没满减的情况
            if (agoPrice == price1[i]) {
                String s;
                if (agoPrice == countPrice) {
                    s = "B";
                } else if (agoPrice < countPrice) {
                    s = "M";
                } else {
                    s = "Z";
                }
                res.append(s);
            }
        }
        System.out.println(res);
    }
}

class Main2 {
    public static String MeituanSend(int[][] num) {
        StringBuilder res = new StringBuilder();
        //商品数量
        int storeNum = num[0][0];
        //商品原价
        int[] price1 = num[1];
        //商品折扣价
        int[] price2 = num[2];
        //折扣规则数量
        int priceNum = num[3][0];
        //满减参数
        int[] countNum = num[4];
        //满减钱数
        int[] deMoney = num[5];
        for (int i = 0; i < price1.length; i++) {
            //原价
            int agoPrice = price1[i];
            //折扣价
            int countPrice = price2[i];
            for (int j = priceNum; j > 0; j--) {
                //能满减的情况
                if (agoPrice >= countNum[j - 1]) {
                    agoPrice -= deMoney[j - 1];
                    String s;
                    if (agoPrice == countPrice) {
                        s = "B";
                    } else if (agoPrice < countPrice) {
                        s = "M";
                    } else {
                        s = "Z";
                    }
                    res.append(s);
                    break;
                }
            }
            //没满减的情况
            if (agoPrice == price1[i]) {
                String s;
                if (agoPrice == countPrice) {
                    s = "B";
                } else if (agoPrice < countPrice) {
                    s = "M";
                } else {
                    s = "Z";
                }
                res.append(s);
            }
        }
        return res.toString();
    }
}